{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4424e793",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from comutils import walk_with_depth\n",
    "df=pd.read_csv(\"S:/sites.csv\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1ee8760d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "95f7c749-f40d-43f1-9511-b509f7182845",
       "rows": [
        [
         "0",
         "skisurfskate.com"
        ],
        [
         "1",
         "rarefigurine.com"
        ],
        [
         "2",
         "animecollectshop.com"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 3
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>domain</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>skisurfskate.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rarefigurine.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>animecollectshop.com</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 domain\n",
       "0      skisurfskate.com\n",
       "1      rarefigurine.com\n",
       "2  animecollectshop.com"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "import pandas as pd\n",
    "\n",
    "# import comutils.get_main_domain_name_from_str\n",
    "from comutils import get_main_domain_name_from_str\n",
    "\n",
    "DESKTOP = r\"C:/Users/Administrator/Desktop\"\n",
    "# 采用table.conf中的第一列数据作为要配置的域名\n",
    "\n",
    "CF_DOMAINS_TABLE = f\"{DESKTOP}/table.conf\"\n",
    "\n",
    "\n",
    "with open(CF_DOMAINS_TABLE, \"r\", encoding=\"utf-8\") as f:\n",
    "    lines = f.readlines()\n",
    "    domains=[]\n",
    "    for line in lines:\n",
    "        # line.split(\" \")\n",
    "        # 数量不定的空白作为分隔符\n",
    "        parts = re.split(r\"\\s+\", line)\n",
    "        domain = parts[0]\n",
    "        domain = get_main_domain_name_from_str(domain)\n",
    "        domains.append(domain)\n",
    "        # print(parts)\n",
    "        # print(domain)\n",
    "    df=pd.DataFrame({\"domain\":domains})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8ecabc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "2c54e8cc-3369-44d4-97fb-f582eb21b3bd",
       "rows": [
        [
         "0",
         "skisurfskate."
        ],
        [
         "1",
         "rarefigurine."
        ],
        [
         "2",
         "animecollectshop."
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 3
       }
      },
      "text/plain": [
       "0        skisurfskate.\n",
       "1        rarefigurine.\n",
       "2    animecollectshop.\n",
       "Name: domain, dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['domain'].str.strip().dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6cc2eee3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "5b7e8faf-ea9a-4224-be7c-85bc73c9de28",
       "rows": [
        [
         "0",
         "skisurfskate.com"
        ],
        [
         "1",
         "rarefigurine.com"
        ],
        [
         "2",
         "animecollectshop.com"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 3
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>domain</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>skisurfskate.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rarefigurine.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>animecollectshop.com</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 domain\n",
       "0      skisurfskate.com\n",
       "1      rarefigurine.com\n",
       "2  animecollectshop.com"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d61bba1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "e454a3c4-584c-41c6-adac-3834c08dde6e",
       "rows": [
        [
         "0",
         "skisurfskate.com"
        ],
        [
         "2",
         "animecollectshop.com"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 2
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>domain</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>skisurfskate.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>animecollectshop.com</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 domain\n",
       "0      skisurfskate.com\n",
       "2  animecollectshop.com"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[[True,False,True]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d4abc4f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "db8d89d9-e171-4b5d-824d-43a74e0a3f85",
       "rows": [
        [
         "0",
         "skisurfskate.com"
        ],
        [
         "1",
         "rarefigurine.com"
        ],
        [
         "2",
         "animecollectshop.com"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 3
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>domain</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>skisurfskate.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rarefigurine.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>animecollectshop.com</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 domain\n",
       "0      skisurfskate.com\n",
       "1      rarefigurine.com\n",
       "2  animecollectshop.com"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2ce61554",
   "metadata": {},
   "outputs": [],
   "source": [
    "all_columns = [\"domain\", \"ip\", \"forward\", \"security\", \"ssl\", \"Note\"]\n",
    "df = pd.DataFrame({\"domain\": domains}, columns=all_columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "afffb3d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "domain",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "ip",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "forward",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "security",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "ssl",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Note",
         "rawType": "object",
         "type": "unknown"
        }
       ],
       "ref": "b6e8ab74-94bc-4b77-b768-fa79fb3cb62a",
       "rows": [
        [
         "0",
         "skisurfskate.com",
         null,
         null,
         null,
         null,
         null
        ],
        [
         "1",
         "rarefigurine.com",
         null,
         null,
         null,
         null,
         null
        ],
        [
         "2",
         "animecollectshop.com",
         null,
         null,
         null,
         null,
         null
        ]
       ],
       "shape": {
        "columns": 6,
        "rows": 3
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>domain</th>\n",
       "      <th>ip</th>\n",
       "      <th>forward</th>\n",
       "      <th>security</th>\n",
       "      <th>ssl</th>\n",
       "      <th>Note</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>skisurfskate.com</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rarefigurine.com</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>animecollectshop.com</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 domain   ip forward security  ssl Note\n",
       "0      skisurfskate.com  NaN     NaN      NaN  NaN  NaN\n",
       "1      rarefigurine.com  NaN     NaN      NaN  NaN  NaN\n",
       "2  animecollectshop.com  NaN     NaN      NaN  NaN  NaN"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "2deaae5e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "domain      skisurfskate.com\n",
      "ip                       NaN\n",
      "forward                  NaN\n",
      "security                 NaN\n",
      "ssl                      NaN\n",
      "Note                     NaN\n",
      "Name: 0, dtype: object\n",
      "domain      rarefigurine.com\n",
      "ip                       NaN\n",
      "forward                  NaN\n",
      "security                 NaN\n",
      "ssl                      NaN\n",
      "Note                     NaN\n",
      "Name: 1, dtype: object\n",
      "domain      animecollectshop.com\n",
      "ip                           NaN\n",
      "forward                      NaN\n",
      "security                     NaN\n",
      "ssl                          NaN\n",
      "Note                         NaN\n",
      "Name: 2, dtype: object\n"
     ]
    }
   ],
   "source": [
    "for _,item in df.iterrows():\n",
    "    print(item)\n",
    "    # print(type(item))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec0ac4f7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
